<?php

namespace app\applet\controller;

use app\share\model\Token;
use app\share\model\WeChat;
use think\Db;
use think\Validate;

class Membertransfer
{
    public function __construct()
    {
        $this->MemberTransfer = new \app\applet\model\MemberTransfer();
        $this->we_chat = new WeChat();
        $this->token = new Token();
    }


    /**
     * 积分发放
     */
    public function score(){
        $input = input();


        $input['member_id'] = get_header_id("token");
        //生成记录订单
        $returnData=$this->MemberTransfer->score($input);

        returnJson(200,'success',$returnData);
    }

    /**
     * 金币发放
     */
    public function coin(){
        $input = input();


        $input['member_id'] = get_header_id("token");

        //生成记录订单
        $returnData=$this->MemberTransfer->coin($input);

        returnJson(200,'success',$returnData);
    }

    /**
     * 获取用户真实姓名
     */
    public function getRealName(){
        $input = input();
        $validate = new Validate([

            ['mobile', 'require', '手机号不能为空'],

        ]);

        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }
        $input['member_id'] = get_header_id("token");

        $returnData=$this->MemberTransfer->getRealName($input);

        returnJson(200,'success',$returnData);
    }

    /**
     * 积分发放 生成记录订单
     */
    public function transferScore(){
        $input = input();
        $validate = new Validate([
            ['trans_type', 'require', '转账类型不能为空'],
            ['score_num', 'require', '转账数量不能为空'],
            ['receive_mobile', 'require', '收款人手机号不能为空'],
            ['receive_name', 'require', '收款人用户名ID不能为空'],
        ]);
        //判断
        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }

        $input['member_id'] = get_header_id("token");

         //生成记录订单
        $returnData=$this->MemberTransfer->transferScore($input);

        returnJson(200,'success',$returnData);
    }

    /**
     * 金币发放 生成记录订单
     */
    public function transferCoin(){
        $input = input();
        $validate = new Validate([
            ['coin_num', 'require', '转账数量不能为空'],
            ['receive_mobile', 'require', '收币人手机号不能为空'],
            ['receive_name', 'require', '收币人用户名ID不能为空'],
        ]);
        //判断
        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }
        $input['member_id'] = get_header_id("token");

        //生成记录订单
        $returnData=$this->MemberTransfer->transferCoin($input);
        returnJson(200,'success',$returnData);
    }

    /**
     * 担保详情
     */
    public function warrantInfo(){
        $member_id= get_header_id("token");
        $returnData=$this->MemberTransfer-> warrantInfo( $member_id);
        returnJson(200,'success',$returnData);
    }

    /**
     * 取消支付
     */
    public function cancelPay(){
        $input = input();
        $validate = new Validate([
            ['trans_sn', 'require', '交易号不能为空'],

        ]);
        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }
        $input['member_id']= get_header_id("token");
        $returnData=$this->MemberTransfer->cancelOrder($input);
        returnJson(200,'success',$returnData);

    }


}